export class PageDto {
  page: number;
  size: number;

  constructor(page: number, size: number) {
    this.page = page;
    this.size = size;
  }

  static of(page: number, size: number): PageDto {
    return new PageDto(page, size);
  }
}

export class BaseResult {
  private static readonly successCode = '200';
  private static readonly errorCode = '500';
  code: string;
  message: string;
  data: any;

  constructor(code: string, message: string, data: any) {
    this.code = code;
    this.message = message;
    this.data = data;
  }

  static of(code: string, message: string, data: any): BaseResult {
    return new BaseResult(code, message, data);
  }

  static async success(data: any): Promise<BaseResult> {
    let resData: any;
    if (data instanceof Promise) {
      resData = await data;
    } else {
      resData = data;
    }
    return new BaseResult(BaseResult.successCode, '成功', resData);
  }

  static async error(msg: string) {
    return new BaseResult(BaseResult.errorCode, '失败', null);
  }
}
